#include "function.h"
#include "struct.h"

/**
 * @brief 按书名查找
 * 
 * @param list 
 * @param book 
 */
void find_title(p_node list, Book book)
{
    printf("请输入您要查找的书籍的书名:");
    char arr[20] = {0};
    int count = 0;          //计数书的本数
    scanf("%19s", arr);                     //限制输入长度，防止溢出
    p_node current = list;
    while(current != NULL)
    {
        if(strcmp(arr, current->data.title) == 0 )
        {
            count ++;           //每找到一本就+1
            //显示这本书的信息
            printf("书名:%s\n作者:%s\nISBN:%s\n出版社:%s\n年份:%d\n库存:%d\n已借出数量:%d\n", \
            current->data.title, current->data.author, current->data.isbn, current->data.publisher, \
            current->data.year, current->data.stock, current->data.borrowed);
            printf("==========\n");      
            //找到一本后不结束，继续往后找，防止后面还有
        }
        current = current->next;
    }
    if (count == 0)
    {
        // 没有要找的书的情况
        printf("该系统中没有您要查找的书籍\n");
    }
    else
    {
        printf("共找到了%d本该书籍\n", count);
    }
}